/**
 * @Description: 定义一个store
 * redux-persist用于解决浏览器刷新导致redux数据丢失的问题
 * @author zhaojiuyi
 * @date 2023/4/14
 */
import {applyMiddleware, combineReducers, createStore} from "redux";
import { persistStore, persistReducer } from 'redux-persist'
import {userReducer} from "./reducers/user.reducer"
import storage from 'redux-persist/lib/storage'
import thunk from "redux-thunk"


/* 整合所有的reducer */
const allReducer = combineReducers({
    user: userReducer,
})

const persistConfig = {
    key: 'root',
    storage,
}

const persistedReducer = persistReducer(persistConfig, allReducer)
const store = createStore(persistedReducer,applyMiddleware(thunk))

export type RootState = ReturnType<typeof allReducer>

export const persistor = persistStore(store)
export default store
